package server;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.util.Random;
import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.DataOutputStream;

public class PasswordTest extends TestCase {

    static Random random = new Random();
    static RandomUtils randomUtils = new RandomUtils();

	public PasswordTest(String name) {
		super(name);
	}

    // Test that the ctor correctly copies the arguments
    public void testCtor() {
        for (int i = 0; i < 300; ++i) {
            long expectedTime = random.nextLong();
            String expectedPassword = randomUtils.getRandomString(5 + random.nextInt(10));
            String expectedUser = randomUtils.getRandomString(5 + random.nextInt(10));
            Password.typeOpt expectedType = 
                random.nextBoolean() ?
                    Password.typeOpt.SIMPLE :
                    Password.typeOpt.EXPERT;
            Password pass = new Password(expectedUser, expectedPassword, expectedType);

            assertEquals(expectedPassword, pass.password);
            assertEquals(expectedUser, pass.user);
            assertEquals(expectedType, pass.type);
        }
    }

	public static Test suite(String[] args) {
		if (args.length == 0) {
			return new TestSuite(PasswordTest.class);
		} else {
			TestSuite testsToRun = new TestSuite();
			for (int i = 0; i < args.length; ++i) {
				testsToRun.addTest(new PasswordTest(args[i]));
			}
			return testsToRun;
		}
	}
}
